import Common from '../common'
var Js = Common('record')
export default {
	name: 'record',
	mixins: [Js],
	components: {},
	data() {
		return {
			fields: [
				{
					key: 'relation_table',
					label: '操作表名',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						style: 'width:160px;margin-right:2px;',
						placeholder: '请输入表名',
						clearable: true,
						defaultValue: '',
						optionDataName: '',
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.relation_table = ['LIKE',['%'+val+'%']];
							} else {
								delete self.searchItem.relation_table;
							};
						},
					},
				},
				{
					key: 'func_name',
					label: '操作',
					application: ['编辑', '添加'],
					formatter: function(val, tests) {
						if (val.func_name == 'update') {
							return '更新修改'
						} else if (val.func_name == 'add') {
							return '添加'
						} else if (val.func_name == 'delete') {
							return '删除'
						} else if (val.func_name == 'loginByUp') {
							return '登录'
						}else if( val.func_name == 'backSql' ){
              return '数据库备份'
            }
					},
          listType: 'normal',
				},
				{
					key: 'relation_user',
					label: '操作用户NO',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						placeholder: '请输入用户NO',
						clearable: true,
						defaultValue: '',
						optionDataName: '',
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.relation_user = ['LIKE',['%'+val+'%']];
							} else {
								delete self.searchItem.relation_user;
							};
						},
					},
				},
				{
					key: 'user',
					label: '操作用户',
					application: ['编辑', '添加'],
					formatter: function(val, tests) {
						return val.user.login_name
					},
          listType: 'normal',
				},
				{
					key: 'create_time',
					label: '操作时间',
					listType: 'normal',
					placeholder: '请选择操作时间',
					header_search: {
						componentName: 'sls-date-time-range',
						style: 'width:160px;margin-right:2px;',
						start_placeholder: '创建开始时间',
						end_placeholder: '创建结束时间',
						changeFunc: function(value, self) {
							if (!value) {
								delete self.searchItem.create_time;
							} else {
								self.searchItem.create_time = ['between', value = value.map(function(e) {
									return e / 1000;
								})]
							};
					
						},
					},
					width:180
				},
				{
					label: '操作',
					listType: 'deal',
					width: 200
				},
			],

			// 按钮配置
			btn_info: [

				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'list',
					text: function(data) {
						return '编辑'
					},
					func: {
						apiName: function(self) {
							return "api_labelUpdate"
						},
						formData: function(self) {
							return self.formData
						},
						postData: function(self) {
							var postData = {
								searchItem: {
									id: self.formData.id,
								},
								data: self.submitData
							};
							if (self.submitData.parentid && self.submitData.parentid == self.formData.id) {
								self.$$notify('父级ID和子级ID重叠', 'fail');
								return false;
							} else {
								return postData;
							};

						}
					},
				},

				{
					type: 'danger',
					icon: 'delete',
					size: 'mini',
					funcType: 'submit',
					position: 'header',
					text: function(data) {
						return '删除选中'
					},
					func: {
						apiName: function(self) {
							return "api_labelUpdate"
						},
						postData: function(self) {
							var deleteArray = [];
							for (var i = 0; i < self.selectionArray.length; i++) {
								deleteArray.push(self.selectionArray[i].id);
							};
							var postData = {
								searchItem: {
									id: ['IN', deleteArray],
								},
								data: {
									status: -1
								}
							};
							return postData;
						}
					},
				},
				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'header',
					text: function(data) {
						return '添加'
					},
					func: {
						apiName: function(self) {
							return "api_labelAdd"
						},
						formData: function(self) {
							var data = {
								title: '',
								description: '',
								mainImg: [],
							};
							return data
						},
						postData: function(self) {
							/* if(!self.submitData.parentid){
								self.$message({
									type: 'info',
									message: '请选择所属类别'
								});
								return ;
							} */
							self.submitData.type = 2;
							var postData = {
								data: self.submitData
							};
							return postData;
						}
					},
				},
				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'list',
					text: function(data) {
						return '关联折扣'
					},
					funcType: 'func',
					func: {
						func: function(self) {
							self.$router.push({
								path: '/home/ratio',
								name: '关联折扣',
								params: {
									id: self.originFormData.id,
									/* product_no: self.originFormData.product_no,
									type: 1, */
									delKeepAlive: true
								}
							});
						},
					},
				},
			],

			searchItem: {

			},
			startSearchItem: {

			},
			optionData: {
				labelOptions: [],
				statusOptions: [{
					text: '启用',
					value: 1
				}, {
					text: '禁用',
					value: -1
				}],
				showOptions:[{
					text:'显示',
					value:1
				},{
					text:'不显示',
					value:0
				}],
				relationOptions:[]
			},
			otherData: {},
			UserInfo: {
				tableName: 'UserInfo',
				searchItem: {},
				key: 'user_no',
				middleKey: 'user_no',
				condition: 'in',
			},

		}

	},

	mounted() {
		const self = this;
		self.table_arguments.tree_props = {
			children: 'child',
			child: 'child',
			hasChildren: 'child'
		}
		self.searchData = self.$$cloneForm(self.searchItem);
		this.init()
	},
	computed: {
		token: function() {
			return this.$store.getters.getToken
		}
	},
	methods: {

		/**
		 * 初始化
		 */
		init() {
			this.initMainData()
		},

		/**
		 * 列表主函数
		 */
		async initMainData(isNew) {

			const self = this;
			const postData = {};

			postData.token = self.$store.getters.getToken;
			if (self.searchItem) {
				postData.searchItem = self.$$cloneForm(self.searchItem)
			};
      postData.paginate = self.$$cloneForm(self.paginate);
			if (JSON.stringify(self.getBefore) != "{}") {
				postData.getBefore = self.$$cloneForm(self.getBefore);
			};
      postData.getAfter = {
        user:{
          tableName:'User',
          middleKey:'relation_user',
          key:'user_no',
          condition:'=',
          info:['login_name']
        }
      }
			var res = await self.$$api_operationLogGet({
				data: postData
			});
			self.mainData = res.info.data;
			self.paginate.count = res.info.total;
			self.table_arguments.loading = false;
		}

	},


}
